<?php
namespace app\adminxcx\controller;
use \think\Controller;
use app\admin\model\Card as CardModel;
use app\admin\model\Job as JobModel;
use app\admin\model\Depart as DepartModel;

class Job extends Controller
{
    protected $CardModel;
    protected $JobModel;
    protected $DepartModel;

    public function __construct()
    {
        if(!session('uid')){
            $this->redirect('index/index');
        }
        $this->CardModel = new CardModel();
        $this->JobModel = new JobModel();
        $this->DepartModel = new DepartModel();
    }

    public function index($gid=-1)
    {
        $query = [
            'ispage' => false,
            'limit' => 12,
            'where' => [
                'gid' => $gid
            ],
            'order' => [
                'create_time' => 'desc'
            ]
        ];
        $DepartRes = $this->DepartModel->getLst($query);
        return view('job/index',[
            'depart'=> $DepartRes
        ]);
        
    }

    public function jobLst($did,$gid=-1)
    {
        $query = [
            'ispage' => false,
            'limit' => 12,
            'where' => [
                'did' => $did,
                'gid' => $gid
            ],
            'order' => [
                'create_time' => 'desc'
            ]
        ];
        $JobRes = $this->JobModel->getLst($query);
        foreach($JobRes as $k => $v){
            $cardNum = $this->CardModel->where([
                'job_id'=>$v['id'],
                'gid' => $gid
            ])->count();
            $JobRes[$k]['count'] = $cardNum;
        }
        $DepartRes = $this->DepartModel->get($did);
        return view('job/joblst',[
            'job'=> $JobRes,
            'depart' => $DepartRes
        ]);
        
    }


    public function lst($id,$gid=-1)
    {
        $query = [
            'ispage' => false,
            'limit' => 12,
            'where' => [
                'job_id' => $id,
                'gid' => $gid
            ],
            'order' => [
                'create_time' => 'desc'
            ]
        ];
        $cardRes = $this->CardModel->getLst($query);
        $JobRes = $this->JobModel->get($id);
        return view('job/lst',[
            'card'=> $cardRes,
            'job'=> $JobRes
        ]);
        
    }

    

 
}
